package week2.day11;

/**
 * @Author fengzihao
 * @Date 2024-04-25 19:28
 */
public class ShapeTest {
    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle(12, 5);
        System.out.println("rectangle.getPerimeter() = " + rectangle.getPerimeter());
        System.out.println("rectangle.getArea() = " + rectangle.getArea());
        Circle circle = new Circle(5);
        System.out.println("circle.getPerimeter() = " + circle.getPerimeter());
        System.out.println("circle.getArea() = " + circle.getArea());
    }
}

abstract class Shape {
    public abstract double getPerimeter();

    public abstract double getArea();
}

class Rectangle extends Shape {

    private double length;
    private double width;

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    @Override
    public double getPerimeter() {
        return (width + length) * 2;
    }

    @Override
    public double getArea() {
        return width * length;
    }

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
}

class Circle extends Shape {

    private double radius;

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }


    @Override
    public double getPerimeter() {
        return 2 * Math.PI * radius;
    }

    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }

    public Circle(double radius) {
        this.radius = radius;
    }
}
